/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ucm.model;
import javax.swing.JOptionPane;
import java.sql.*;
import cp3120_p.DAO;

public class UCDelete_Model {
    private String name;
    private String passwod;
    private DAO DbConn;

    public UCDelete_Model(String name, String passwod) {
        this.name = name;
        this.passwod = passwod;
        DbConn = new DAO();
    }

    public DAO getDbConn() {
        return DbConn;
    }

    public void setDbConn(DAO DbConn) {
        this.DbConn = DbConn;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    public boolean rundelete()
    {
        Connection con = DbConn.getConnection();
        if (con == null) {
            return false;
        }
        try {
            Statement stmt = con.createStatement(ResultSet.CONCUR_UPDATABLE, ResultSet.CONCUR_UPDATABLE);
            ResultSet res;
            res = stmt.executeQuery("select * from userinfo where username = " + "'" + name + "'");
            res.first();
            if (passwod.equals(res.getString("password"))) {
                 stmt.executeUpdate("DELETE FROM userinfo WHERE username = '"
                        + name + "'");
                 JOptionPane.showMessageDialog(null, "Delete OK");
                 return true;
            }
            JOptionPane.showMessageDialog(null, "PassWord is not cruuect");
            return false;
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "no this user");
            return false;
        }
    }
}
